package com.idroc.coelacanth.core.membership;

import org.jboss.netty.buffer.ChannelBuffer;

import com.idroc.coelacanth.core.message.AbstractMessage;
 
/**
 * 端点成员请求消息
 * @author yuyoo (yuyoo4j@163.com)
 * @date Dec 6, 2009 12:16:33 PM
 */
public class MemberSetRequestMessage extends AbstractMessage {
	
	private Endpoint from = null;
	
	private int requestMemberStateCode = 0;

	@Override
	public void decode(ChannelBuffer ib) {
		
		from = new Endpoint();
		from.setHost(decodeString(ib));
		from.setPort(ib.readInt()); 
		requestMemberStateCode = ib.readInt();
	}

	@Override
	public void encode(ChannelBuffer ob) {
		
		encodeString(ob, from.getHost());
		ob.writeInt(from.getPort());
		ob.writeInt(requestMemberStateCode);
	}

	public Endpoint getFrom() {
		return from;
	}

	public void setFrom(Endpoint from) {
		this.from = from;
	}

	public int getRequestMemberStateCode() {
		return requestMemberStateCode;
	}

	public void setRequestMemberStateCode(int requestMemberStateCode) {
		this.requestMemberStateCode = requestMemberStateCode;
	}
	
	@Override
	public String toString() {

		StringBuilder sb = new StringBuilder();
		sb.append("MemberSetRequestMessage[");
		sb.append("sn:").append(this.getSN()).append(",");
		sb.append("from:").append(from).append(",");
		sb.append("requestMemberStateCode:").append(requestMemberStateCode);
		sb.append("]");
		return sb.toString();
	}
}
